﻿#include "ArmadilloElder.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../MirEnvir/Envir.h"
#include "../../../Shared/ServerPackets.h"
#include "../../../Shared/Data/Stat.h"
#include "../DelayedAction.h"
#include "../../../Shared/Enums.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    ArmadilloElder::ArmadilloElder(MonsterInfo *info) : Armadillo(info)
    {
    }

    void ArmadilloElder::Attack()
    {
        if (!getTarget()->IsAttackTarget(this))
        {
            setTarget(nullptr);
            return;
        }

        ShockTime = 0;

        setDirection(Functions::DirectionFromPoint(getCurrentLocation(), getTarget()->getCurrentLocation()));

        ActionTime = getEnvir()->getTime() + 300;
        AttackTime = getEnvir()->getTime() + AttackSpeed;

        switch (getEnvir()->Random->Next(0, 6))
        {
            case 0:
            {
                    Retreat();
                    _runAway = true;
            }
                break;
            case 1:
            {
                    S::ObjectAttack *tempVar = new S::ObjectAttack();
                    tempVar->ObjectID = ObjectID;
                    tempVar->Direction = getDirection();
                    tempVar->Location = getCurrentLocation();
                    tempVar->Type = 1;
                    Broadcast(tempVar);
                    int damage = GetAttackPower(Stats[Stat::MinDC], Stats[Stat::MaxDC]);
                    if (damage == 0)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    getTarget()->Pushed(this, getDirection(), 2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            }
                break;
            default:
            {
                    S::ObjectAttack *tempVar2 = new S::ObjectAttack();
                    tempVar2->ObjectID = ObjectID;
                    tempVar2->Direction = getDirection();
                    tempVar2->Location = getCurrentLocation();
                    Broadcast(tempVar2);
                    int damage = GetAttackPower(Stats[Stat::MinDC], Stats[Stat::MaxDC]) * 2;
                    if (damage == 0)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    DelayedAction *action = new DelayedAction(DelayedType::Damage, getEnvir()->getTime() + 400, {getTarget(), damage, DefenceType::ACAgility});
                    ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
            }
                break;
        }
    }

    void ArmadilloElder::CompleteRangeAttack(std::vector<std::any> &data)
    {
        //Retreat attack does no damage
    }
}
